package org.travel_system.mapper;

import org.apache.ibatis.annotations.*;
import org.travel_system.pojo.Reservation;

import java.util.List;

@Mapper
public interface ReservationMapper {

    //查询所有预订信息
    @Select("SELECT * FROM room_reservations")
    List<Reservation> findAllReservations();

    //查询用户预定信息
    @Select("select * from room_reservations where tourist_id = #{userId}")
    List<Reservation> findUserReservations(int userId);

    //查询单个预定信息
    @Select("select * from room_reservations where reservation_id = #{id}")
    Reservation findReservationById(int id);
    
    //创建预定信息
    @Insert("insert into room_reservations(room_number, tourist_id, CheckInDate, CheckOutDate, is_reserved,hotel_name) " +
            "values (#{roomNumber}, #{touristId}, #{checkInDate}, #{checkOutDate},#{isReserved},#{hotelName})")
    int createReservation(Reservation reservation);

    //更新预定信息
    @Update("update room_reservations set hotel_name=#{hotelName}, room_number = #{roomNumber}, tourist_id = #{touristId},CheckInDate = #{checkInDate}, CheckOutDate = #{checkOutDate}, is_reserved = #{isReserved} where reservation_id = #{reservationId} ")
    int updateReservation(Reservation reservation);

    //删除预定信息
    @Delete("delete from room_reservations where reservation_id = #{id}")
    int deleteReservation(int id);
}
